//
//  HNSH_AgentHeaderView.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/3/4.
//

#import "HNSH_AgentHeaderView.h"

@interface HNSH_AgentHeaderItemView : UIView

/* leftLabel */
@property (nonatomic, strong) UILabel *leftLabel;
/* rightLabel */
@property (nonatomic, strong) UILabel *rightLabel;
/* lineView */
@property (nonatomic, strong) UIView *lineView;

@end

@implementation HNSH_AgentHeaderItemView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self configUI];
    }
    return self;
}

- (void)configUI {
    [self addSubview:self.leftLabel];
    [self addSubview:self.rightLabel];
//    [self addSubview:self.lineView];
}

#pragma mark lazy
-(UILabel *)leftLabel {
    if (!_leftLabel) {
        _leftLabel = [[UILabel alloc]initWithFrame:CGRectMake(16, 0, 300, self.height)];
        _leftLabel.textColor = [UIColor appGray666LabelColor];
        _leftLabel.font = [UIFont systemFontOfSize:12];
    }
    return _leftLabel;
}

-(UILabel *)rightLabel {
    if (!_rightLabel) {
        _rightLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.width-220, 0, 200, self.height)];
        _rightLabel.textColor = [UIColor appGrayLabelColor];
        _rightLabel.font = [UIFont systemFontOfSize:12];
        _rightLabel.textAlignment = NSTextAlignmentRight;
    }
    return _rightLabel;
}

- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [[UIView alloc]initWithFrame:CGRectMake(20, self.height-1, self.width-40, 1)];
        _lineView.backgroundColor = [UIColor colorWithHexString:@"#F2F3F6"];
    }
    return _lineView;
}

@end

@interface HNSH_AgentHeaderView ()

/* topVipBgImgV */
@property (nonatomic, strong) UIImageView *topVipBgImgV;
/* topNameLabel */
@property (nonatomic, strong) UILabel *topNameLabel;
/* topTimeLabel */
@property (nonatomic, strong) UILabel *topTimeLabel;

@end

@implementation HNSH_AgentHeaderView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self configUI];
    }
    return self;
}

- (void)setDict:(NSDictionary *)dict {
    _dict = dict;
    [self configTopView];
    [self configBottomViewWithAry:dict[@"items"]];
    
//    //代理特殊状态 special_status  0:实习期 1:正式代理
//    self.sxBgImgV.hidden = self.sxTitleLabel.hidden = self.sxDesLabel.hidden = [dict[@"special_status"] integerValue] == 1;
//    self.sxBgImgV.image = [UIImage imageNamed:[NSString stringWithFormat:@"mine_agent_top_right_level_%@",dict[@"level"]]];
}

- (void)configUI {
}

- (void)configTopView {
    [self addSubview:self.topVipBgImgV];
    [self addSubview:self.topNameLabel];
    [self addSubview:self.topTimeLabel];
    
    [self.topVipBgImgV sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",self.dict[@"icon"]]]];
    self.topNameLabel.text = [NSString stringWithFormat:@"%@",self.dict[@"parent_region_name"]];
    self.topTimeLabel.text = [NSString stringWithFormat:@"%@",self.dict[@"expire_time"]];
}

- (void)configBottomViewWithAry:(NSArray *)ary {
    
    UIView *bottomView = [[UIView alloc] init];
    bottomView.frame = CGRectMake(16, 84, kScreenWidth-32, 57+ary.count*16);
    bottomView.backgroundColor = [UIColor appWhiteLabelColor];
    // blur
    UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    UIVisualEffectView *visualView = [[UIVisualEffectView alloc]initWithEffect:blurEffect];
    visualView.frame = CGRectMake(20, 243, kScreenWidth-40, 88+ary.count*50);
    bottomView.layer.cornerRadius = 8;
    bottomView.layer.shadowColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.1000].CGColor;
    bottomView.layer.shadowOffset = CGSizeMake(0,3);
    bottomView.layer.shadowOpacity = 1;
    bottomView.layer.shadowRadius = 6;
    [self addSubview:bottomView];
    
    UIImageView *imgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mine_agent_bottom_icon"]];
    imgV.frame = CGRectMake(16, 13, 20, 20);
    [bottomView addSubview:imgV];
    
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(44, 12, 200, 22)];
    titleLabel.textColor = [UIColor appBlackLabelColor];
    titleLabel.font = [UIFont boldSystemFontOfSize:16];
    titleLabel.text = @"区域数据";
    [bottomView addSubview:titleLabel];
    
    for (int i = 0; i < ary.count; i ++) {
        NSDictionary *dic = ary[i];
        HNSH_AgentHeaderItemView *view = [[HNSH_AgentHeaderItemView alloc]initWithFrame:CGRectMake(0, 45+16*i, bottomView.width, 16)];
        view.leftLabel.text = [NSString stringWithFormat:@"%@%@",dic[@"left_text"],dic[@"right_text"]];
//        view.rightLabel.text = [NSString stringWithFormat:@"%@",dic[@"right_text"]];
        [bottomView addSubview:view];
    }
}

#pragma mark lazy

- (UIImageView *)topVipBgImgV {
    if (!_topVipBgImgV) {
        _topVipBgImgV = [[UIImageView alloc]initWithFrame:CGRectMake(16, 16, 52, 52)];
        _topVipBgImgV.image = [UIImage imageNamed:@"mine_agent_top_icon"];
    }
    return _topVipBgImgV;
}

-(UILabel *)topNameLabel {
    if (!_topNameLabel) {
        _topNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(80, 17, 250, 25)];
        _topNameLabel.textColor = [UIColor appBlackLabelColor];
        _topNameLabel.font = [UIFont boldSystemFontOfSize:18];
    }
    return _topNameLabel;
}

-(UILabel *)topTimeLabel {
    if (!_topTimeLabel) {
        _topTimeLabel = [[UILabel alloc]initWithFrame:CGRectMake(80, 46, 260, 20)];
        _topTimeLabel.textColor = [UIColor appGrayLabelColor];
        _topTimeLabel.font = [UIFont systemFontOfSize:14];
    }
    return _topTimeLabel;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
